package oving2;
public class ArgumentStack {
	public static double[] arguments={};
	public static double[] copyArray(double[] original, int newSize) {
		double[] newArray = new double[newSize];
		// copy the old elements into the same positions
		System.arraycopy(original, 0, newArray, 0, Math.min(original.length, newArray.length));
		// return new array
		return newArray;
	}
	public static void print(String prefix, String separator, String suffix) {
		System.out.print(prefix);
		for (int i = 0; i < arguments.length; i++) {
			// make sure the separator is not printed before the first value
			if (i > 0) {
				System.out.print(separator);
			}
			System.out.print(arguments[i]);
		}
		System.out.print(suffix);
	}

	public static double peek(double arg){
		if (!(arguments.length==0)){
			return arguments[arguments.length-1];	
		}
		else{
			return arg;
		}
	}
	public static void push(double arg){
		arguments =copyArray(arguments,(arguments.length+1));
		arguments[arguments.length-1]=arg;
	}
	public static double pop(double arg){
		if(arguments.length==0){
			return arg;
		}
		else{
			double temp=arguments[arguments.length-1];
			arguments =copyArray(arguments,arguments.length-1);
			return temp;
		}
	}
	
}
